#include "herm/base/utils/misc.h"
#include "udp_peer.h"
#include "udp_session.h"

UDPSession::UDPSession()
{
}

UDPSession::~UDPSession()
{
}

void UDPSession::Init(UDPPeer* peer, int index)
{
	m_peer = peer;
	m_index = index;
}

void UDPSession::Reset(const herm::Address& remoteAddr)
{
	m_state = herm::ST_SUCCESS;
	m_recvBytes = 0;
	m_sendBytes = 0;
	m_remoteAddr = remoteAddr;
}

void UDPSession::SetStateCode(int state)
{
	m_state = state;
}

int UDPSession::GetIndex()
{
	return m_index;
}

int UDPSession::Fetch(char* buf, int& len) const
{
	if ((int)m_state != herm::ST_SUCCESS)
		return m_state;

	return m_peer->Fetch(buf, len);
}

int UDPSession::Push(const char* buf, int len)
{
	HERM_ASSERT(len > 0);
	HERM_ASSERT(len <= m_peer->m_peerParam.maxUDPMsgSize);

	return m_peer->Push(buf, len, m_remoteAddr);
}

const herm::Address& UDPSession::GetLocalAddr() const
{
	return m_peer->GetLocalAddr();
}

const herm::Address& UDPSession::GetRemoteAddr() const
{
	return m_remoteAddr;
}

herm::IPeer* UDPSession::GetPeer()
{
    return nullptr;
}

const herm::IPeer* UDPSession::GetPeer() const
{
    return nullptr;
}